package logic

import (
	"bw-renting/user-rpc/model"
	"context"
	"errors"

	"bw-renting/user-rpc/internal/svc"
	"bw-renting/user-rpc/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserRegisterLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserRegisterLogic {
	return &UserRegisterLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserRegisterLogic) UserRegister(in *user.UserRegisterRequest) (*user.UserRegisterResponse, error) {
	// todo: add your logic here and delete this line
	u := model.User{Username: in.UserName, Password: in.Password}
	users, _ := model.UserRegister(&u)
	if users.ID == 0 {
		return &user.UserRegisterResponse{}, errors.New("注册失败")
	}
	return &user.UserRegisterResponse{
		UserId: int64(users.ID),
	}, nil
}
